package wint.lang.utils;

import java.io.IOException;
import java.io.InputStream;

import wint.lang.io.FastByteArrayOutputStream;

public class StreamUtil {
	
	public static byte[] read(InputStream is) throws IOException {
		FastByteArrayOutputStream bos = new FastByteArrayOutputStream();
		IoUtil.copy(is, bos);
		IoUtil.close(is);
		IoUtil.close(bos);
		return bos.toByteArray();
	}
	
	public static String readAsString(InputStream is, String charset) throws IOException {
		return new String(read(is), charset);
	}
	
	public static String readAsString(InputStream is) throws IOException {
		return new String(read(is));
	}

}
